package realm.inorder.itmill.ui.window;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import realm.inorder.itmill.ui.panel.initial.InitialLayout;
import realm.inorder.itmill.ui.panel.initial.RegisterWindow;
import realm.inorder.itmill.ui.panel.logged.LoggedLayoutController;

import com.itmill.toolkit.terminal.ClassResource;
import com.itmill.toolkit.ui.GridLayout;
import com.itmill.toolkit.ui.Label;
import com.itmill.toolkit.ui.Window;

@Component
public class MainWindow extends Window {

	protected final Logger logger = Logger.getLogger(getClass());

	private GridLayout mainGridLayout;

	@Autowired
	private InitialLayout initialLayout;

	@Autowired
	private LoggedLayoutController loggedLayoutController;

	@Autowired
	private RegisterWindow registerWindow;
	
	public MainWindow() {
	}

	public void init() {
		this.removeAllComponents();
		
		Label label = new Label();
		label.setIcon(new ClassResource("/images/InOrder2_3.png", getApplication()));
		
		mainGridLayout = new GridLayout(1, 2);
		
		mainGridLayout.setStyleName("mainWindow");
		mainGridLayout.setMargin(true);
		
		mainGridLayout.addComponent(label);
		mainGridLayout.addComponent(initialLayout);
		
		this.setLayout(mainGridLayout);
		
		this.addWindow(registerWindow);
	}
	
	public void clearLayout() {
		mainGridLayout.removeComponent(0, 1);
	}
	
	public void showInitialLayout() {
		clearLayout();
		mainGridLayout.addComponent(initialLayout);
	}
	
	public void showLoggedLayout() {
		clearLayout();
		loggedLayoutController.showLoggedLayout(mainGridLayout);
//		mainGridLayout.addComponent(loggedLayout);
	}
	
}
